const { app, BrowserWindow } = require("electron")
const { join, resolve } = require("path")
const createWindow = () => {
  const win = new BrowserWindow({
    "width": 800,
    "height": 600,
    "webPreferences": {
      // 预加载脚本
      "preload": join(__dirname, "index", "preload.js"),
      "nodeIntegration": true,
      // 在外部引入的js中获取不到remote, 在main.js中也获取不到remote模块
      "enableRemoteModule": true,
      "contextIsolation": false,
      // webview的宽高设置
      "webviewTag": true
    }
  })
  // 消除控制台的警告
  process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = true
  // 忽略所有鼠标点击事件
  // main_window.setIgnoreMouseEvents(true)
  // 打开控制面板
  // main_window.webContents.openDevTools()
  // 加载首页
  win.loadFile("index/index.html")
}
app.whenReady().then(() => {
  createWindow()
})

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") app.quit()
})

app.whenReady().then(() => {
  createWindow()
  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})